package com.baseweb.webadmin.core.model.mapper;

import com.baseweb.webadmin.core.model.pojo.ByAd;
import com.baseweb.webadmin.core.model.pojo.ByAdExample;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;

public interface ByAdMapper {
    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_ad
     *
     * @mbggenerated Sun Apr 23 22:44:54 CST 2017
     */
    int countByExample(ByAdExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_ad
     *
     * @mbggenerated Sun Apr 23 22:44:54 CST 2017
     */
    int deleteByExample(ByAdExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_ad
     *
     * @mbggenerated Sun Apr 23 22:44:54 CST 2017
     */
    @Delete({
        "delete from by_ad",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_ad
     *
     * @mbggenerated Sun Apr 23 22:44:54 CST 2017
     */
    @Insert({
        "insert into by_ad (position_id, img_url, ",
        "name, descn, status, ",
        "create_time, ",
        "update_time, ",
        "sort, url, subtitle, ",
        "parent_id, entity_Id, province,city,district,isCheck)",
        "values (#{positionId,jdbcType=INTEGER}, #{imgUrl,jdbcType=VARCHAR}, ",
        "#{name,jdbcType=VARCHAR}, #{descn,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER}, ",
        "#{createTime,jdbcType=TIMESTAMP,typeHandler=com.baseweb.mybatis.typehandler.JodaDateTime2TimestampTypeHandler}, ",
        "#{updateTime,jdbcType=TIMESTAMP,typeHandler=com.baseweb.mybatis.typehandler.JodaDateTime2TimestampTypeHandler}, ",
        "#{sort,jdbcType=INTEGER}, #{url,jdbcType=VARCHAR}, #{subtitle,jdbcType=VARCHAR}, ",
        "#{parentId,jdbcType=INTEGER}, #{entityId,jdbcType=INTEGER}, " +
                "#{province,jdbcType=VARCHAR}, #{city,jdbcType=VARCHAR}, #{district,jdbcType=VARCHAR}, #{isCheck,jdbcType=INTEGER})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Integer.class)
    int insert(ByAd record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_ad
     *
     * @mbggenerated Sun Apr 23 22:44:54 CST 2017
     */
    int insertSelective(ByAd record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_ad
     *
     * @mbggenerated Sun Apr 23 22:44:54 CST 2017
     */
    List<ByAd> selectByExample(ByAdExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_ad
     *
     * @mbggenerated Sun Apr 23 22:44:54 CST 2017
     */
    @Select({
        "select",
        "id, position_id, img_url, name, descn, status, create_time, update_time, sort, ",
        "url, subtitle, parent_id, entity_Id, province, city, district, isCheck",
        "from by_ad",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @ResultMap("BaseResultMap")
    ByAd selectByPrimaryKey(Integer id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_ad
     *
     * @mbggenerated Sun Apr 23 22:44:54 CST 2017
     */
    int updateByExampleSelective(@Param("record") ByAd record, @Param("example") ByAdExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_ad
     *
     * @mbggenerated Sun Apr 23 22:44:54 CST 2017
     */
    int updateByExample(@Param("record") ByAd record, @Param("example") ByAdExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_ad
     *
     * @mbggenerated Sun Apr 23 22:44:54 CST 2017
     */
    int updateByPrimaryKeySelective(ByAd record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_ad
     *
     * @mbggenerated Sun Apr 23 22:44:54 CST 2017
     */
    @Update({
        "update by_ad",
        "set position_id = #{positionId,jdbcType=INTEGER},",
          "img_url = #{imgUrl,jdbcType=VARCHAR},",
          "name = #{name,jdbcType=VARCHAR},",
          "descn = #{descn,jdbcType=VARCHAR},",
          "status = #{status,jdbcType=INTEGER},",
          "create_time = #{createTime,jdbcType=TIMESTAMP,typeHandler=com.baseweb.mybatis.typehandler.JodaDateTime2TimestampTypeHandler},",
          "update_time = #{updateTime,jdbcType=TIMESTAMP,typeHandler=com.baseweb.mybatis.typehandler.JodaDateTime2TimestampTypeHandler},",
          "sort = #{sort,jdbcType=INTEGER},",
          "url = #{url,jdbcType=VARCHAR},",
          "province = #{province,jdbcType=VARCHAR},",
          "city = #{city,jdbcType=VARCHAR},",
          "district = #{district,jdbcType=VARCHAR},",
          "subtitle = #{subtitle,jdbcType=VARCHAR},",
          "parent_id = #{parentId,jdbcType=INTEGER},",
          "entity_Id = #{entityId,jdbcType=INTEGER},",
          "isCheck = #{isCheck,jdbcType=INTEGER}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(ByAd record);

    @Select({
            "select",
            "id, position_id, img_url, name, descn, status,  sort, ",
            "url, subtitle, parent_id, entity_Id, price, comment_count, view_count, good_evaluation,isCheck,update_time ",
            "from by_ad ",
            "where status = 1 and isCheck = 1 and position_id = #{0} and (city=#{2} or #{2}='') ",
            "order by sort desc limit #{1} "
    })
    @ResultMap("BaseResultMap")
    List<ByAd> findAllByPositionId(int positionId,int limit,String city);

    @Select({
            "select",
            "id, position_id, img_url, name, descn, status,  sort, ",
            "url, subtitle, parent_id, entity_Id, price, comment_count, view_count, good_evaluation,isCheck,update_time ",
            "from by_ad ",
            "where status = 1 and isCheck = 1 and parent_id = #{0} and (city=#{2} or #{2}='') ",
            "order by update_time desc limit #{1} "
    })
    @ResultMap("BaseResultMap")
    List<ByAd> findAllByParentId(int parentId,int limit,String city);

    @Select({
            "select",
            "id, position_id, img_url, name, descn, status,  sort, ",
            "url, subtitle, parent_id, entity_Id, price, comment_count, view_count, good_evaluation,isCheck,update_time ",
            "from by_ad ",
            "where parent_id = #{0} "
    })
    @ResultMap("BaseResultMap")
    List<ByAd> findByAdParentId(int parentId);
}